package com.zp.api.imagesearch;

import com.zp.api.imagesearch.domain.ImageSearchResult;
import com.zp.api.imagesearch.sub.GetImageList;
import com.zp.api.imagesearch.sub.GetImageListAddress;
import com.zp.api.imagesearch.sub.GetImagePageUrl;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 图片搜索服务(门面模式)
 */
@Slf4j
public class ImageSearchFacade {

    /**
     * 搜索图片
     *
     * @param imageUrl 要以图搜图的图片地址
     * @return 搜搜成功的图片列表
     */
    public static List<ImageSearchResult> searchImage(String imageUrl) {
        String imagePageUrl = GetImagePageUrl.getImagePageUrl(imageUrl);
        String imageFirstUrl = GetImageListAddress.getImageAddress(imagePageUrl);
        return GetImageList.getImageList(imageFirstUrl);
    }

    public static void main(String[] args) {
        // 测试以图搜图功能
        String imageUrl = "https://tse1-mm.cn.bing.net/th/id/OIP-C.StrDRqennoZNbzSPZapKZwAAAA?w=277&h=180&c=7&r=0&o=7&dpr=1.5&pid=1.7&rm=3";
        List<ImageSearchResult> resultList = searchImage(imageUrl);
        System.out.println("结果列表" + resultList);
    }
}
